package org.r505.chatroom.global.controller;

import javax.websocket.Session;

import org.r505.chatroom.global.core.InstanceFactory;

/**
 * 处理器转发类
 * @author ljj
 *
 */
public class RequestHandler {
	/**
	 * 处理器
	 * @param mapping 
	 * @param param
	 * @return
	 * @throws Throwable
	 */
	public static Object handle(Session session, String mapping, String param) throws Throwable{
		String id = ControllerFactory.getId(mapping); //获取mapping对应id
		String methodName = ControllerFactory.getMethodName(mapping); //获取mapping对应方法名
		Object instance = InstanceFactory.getInstance(id); //根据id获取实例
		Class<?> clazz = instance.getClass(); //获取class
		return clazz.getMethod(methodName, Session.class, String.class).invoke(instance, session, param); //调用方法
	}
}
